package pl.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

@SuppressWarnings("unchecked")
public class DataSource {
	
	List list = new ArrayList();

    /** Creates a new instance of DataSource */

    public DataSource() {

        Calendar calendar = Calendar.getInstance();

        Celebrity fonda = new Celebrity();
        fonda.setFirstName("Jane");
        fonda.setLastName("Fonda");
        fonda.setOccupation("Actress");
        calendar.set(1937, 11, 21);
        fonda.setDateOfBirth(calendar.getTime());
        fonda.setId(1);
        list.add(fonda);

        Celebrity gallo = new Celebrity();
        gallo.setFirstName("Ernest");
        gallo.setLastName("Gallo");
        gallo.setOccupation("Wine-maker");
        calendar.set(1909, 2, 18); // Months are 0-based (2 is March)
        gallo.setDateOfBirth(calendar.getTime());
        gallo.setId(2);
        list.add(gallo);

        Celebrity gates = new Celebrity();
        gates.setFirstName("Bill");
        gates.setLastName("Gates");
        gates.setOccupation("Programmer ;)");
        calendar.set(1955, 9, 28);
        gates.setDateOfBirth(calendar.getTime());
        gates.setId(3);
        list.add(gates);

        Celebrity jolie = new Celebrity();
        jolie.setFirstName("Angelina");
        jolie.setLastName("Jolie");
        jolie.setOccupation("Actress");
        calendar.set(1975, 5, 4);
        jolie.setDateOfBirth(calendar.getTime());
        jolie.setId(4);
        list.add(jolie);       
    }

    public List getCelebrities() {
        return list;
    }

    public Celebrity getCelebrityById(int id) {
        for (Iterator i = list.iterator(); i.hasNext();) {
            Celebrity celebrity = (Celebrity)i.next();
            if (celebrity.getId() == id) return celebrity;
        }
        return null;
    }   
    
    public void addCelebrity(Celebrity celebrity) {

    	   list.add(celebrity);
    }
    
    public int getNewId() {

    	   return list.size() + 1;
    }
    
    
}
